package com.example.pong;

import android.graphics.Canvas;
import android.graphics.Color;
import android.view.MotionEvent;
import sheep.game.*;
import sheep.input.TouchListener;

public class GameState extends State implements TouchListener{

	private World gameWorld;
	private GameLayer gameLayer;

	public GameState(int width, int height){
		gameWorld = new World();
		gameLayer = new GameLayer(width, height);
		gameWorld.addLayer(gameLayer);
	}
	
	@Override
	public boolean onTouchDown(MotionEvent event){
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			float x = event.getRawX();
			gameLayer.getPlayer().setSpeed(x);
			break;
		case MotionEvent.ACTION_UP:
			gameLayer.getPlayer().stopPlayer();
		default:
			break;
		}
		return false;
	}
	
	@Override
	public boolean onTouchUp(MotionEvent event){
		switch (event.getAction()) {
		case MotionEvent.ACTION_UP:
			gameLayer.getPlayer().stopPlayer();
			break;

		default:
			break;
		}
		return false;
	}

	@Override
	public void draw(Canvas canvas){
		canvas.drawColor(Color.BLACK);
		gameWorld.draw(canvas);
	}

	@Override
	public void update(float dt){
		gameWorld.update(dt);
	}
}
